<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>${tabTitle}</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <form id="ins_cfg_info_edit_form">
                    <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_33">
                        <div class="label">机构名称</div>
                        <div class="field">
                            <span>${fundRasInsNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">客户名称</div>
                        <div class="field">
                            <span>${cstNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">身份证号</div>
                        <div class="field">
                            <span id="cstPyNm">${certNo}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">现居住地</div>
                        <div class="field">
                            <jsp:include page="../../system/sysRegion/region.jsp" flush="true">
                                <jsp:param name="regionShowLvl"  value="2"/>
                            </jsp:include>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_100">
                        <div class="label">居住地详细地址</div>
                        <div class="field">
                            <input name="postAddr" id="postAddr" type="text" class="ui-textbox" value="${postAddr}" validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>

                    <!-- hide data -->
                    <div class="fieldBox col_100" style="display: none;">
                        <div class="field">
                            <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
                        </div>
                    </div>
                </div>
                <div id="saveInsCfgDiv" class="btnsBox" style="text-align: center">
                    <span id="saveInsCfg" class="sq-button sq-button-round" onclick="return saveInfo();">保存</span>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">

    var detailFlag = '${detailFlag}';
    var updateFlag = '${updateFlag}';
    var fromCAFlag = '${fromCAFlag}';
    var fromCMFlag = '${fromCMFlag}';
    $(function(){
        initData();
        disabledInput();
        enableFields();
    });

    /**
     * 初始化
     */
    function initData() {
        $("#ins_cfg_info_edit_form").ligerForm({
            validate: true
        });
        //区域 省、市
        setRgnProvCdUpdataValue('${postProvince}');
        setRgnCityCdUpdataValue('${postCity}');
    }
    /**
     * 查看详情页面置灰 不可编辑
     **/
    function disabledInput() {

        if(detailFlag == "true") {
            liger.get("postAddr").setDisabled();
            liger.get("rgnProvCd").setDisabled();
            liger.get("rgnCityCd").setDisabled();
            $("#saveInsCfgDiv").hide();
        }
    }

    /**
     * 是否展示保存按钮
     **/
    function enableFields() {

        if (null != fromCAFlag && "true" == fromCAFlag) {

            $("#saveInsCfgDiv").show();
        }
        if (null != fromCMFlag && "true" == fromCMFlag) {

            $("#saveInsCfgDiv").show();
        }
    }

    /**
     * 保存表单数据
     */
    function saveInfo(){

        var ligerForm = liger.get("ins_cfg_info_edit_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = ligerForm.getData();


        var rgnProvCd = getRgnProvCd();
        var rgnCityCd = getRgnCityCd();
        if(!rgnProvCd || ' ' == rgnProvCd){
            top.$.ligerDialog.SQalert({content: "居住地-省为空，请维护!", SQ_type: "error"});
            return false;
        }
        if(!rgnCityCd || ' ' == rgnCityCd){
            top.$.ligerDialog.SQalert({content: "居住地-市为空，请维护!", SQ_type: "error"});
            return false;
        }
        if (!$("#postAddr").val()) {
            top.$.ligerDialog.SQalert({content: "居住地详细地址为空，请维护!", SQ_type: "error"});
            return false;
        }


        data["cstId"] = $("#cstId").val();
        data["postAddr"] = $("#postAddr").val();//居住地详细地址
        data["postProvince"] = getRgnProvCd();//居住地-省
        data["postCity"] = getRgnCityCd();//居住地-市

        var url = '<%=path%>/institution/tyfl/save.do';
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    disabledInput();
                    UIUtils.alertSuccessHold1(msg.info);
                    resetAccResCd();
                    disabledBecaofCheck();
                } else {
                    UIUtils.alertErrorHold1(msg.info);
                }
            }
        });
    }
</script>
</body>
</html>